function checkchuli(id) {
    $.get(baseURL + "sys/tianan/info/" + id, function (r) {
        vm.tianan = r.tianan;
        vm.tianan.lianstatus = 1;
        layer.open({
            title: vm.tianan.title,
            shade: 0.5,
            type: 1,
            skin: 'layui-layer-molv',
            area: ['800px', '480px'],
            btn: ['提交'],
            content: '<form id="test">' +
                '<div id="test1" style="padding:10px 10px  0 10px">' +
                '<div class="user"> </div>' +
                '<div class="form-group  " style="text-align: center;" > 案由分析</div>' +
                '<div class="form-group wenzi anyoufenxi" style="margin-top: 5px;border: 1px #999 solid;  padding: 5px;"></div>' +
                '<div class="form-group " style="text-align: center;" > 措施建议</div>' +
                '<div class="form-group wenzi  cuoshijianyi" style="margin-top: 5px;border: 1px #999 solid; padding: 5px;"></div>' +
                '<div class="form-group " style="line-height: 35px; margin-bottom: 0">' +
                '      <input type="radio" class="check" checked style="margin: 0 10px" name="lian" value="2" title="受理">受理' +
                '      <input type="radio" class="check" style="margin: 0 10px" name="lian" value="3" title="退回" >退回</div>' +
                '<div class="form-group depts " style="margin: 5px;"> ' +
                '经办人：<select class="dept selectpicker"   data-live-search="true"></select></div>' +
                '<div class="form-group shuru" style="display: none; margin: 10px;" ><textarea  name=""  placeholder="退回原因 " class="layui-textarea  liancause"></textarea></div>' +
                '</div></form>',
            success: function (layero, index) {

                $(".user").html("提案人：" + vm.tianan.creatusername + "&nbsp; 所属部门：" + vm.tianan.deptIdName);

                //评分组件代码
                $(".anyoufenxi").html("<p>" + vm.tianan.anyoufenxi + "</p>");
                $(".cuoshijianyi").html("<p>" + vm.tianan.cuoshijianyi + "</p>");
                var dict = getuserlist(getuser().deptId);
                var sel = "";

                for (var i = 0; i < dict.length; i++) {
                    sel += '<option  value="' + dict[i].userId + '">' + dict[i].realname + '</option>'
                }
                $(".dept").html(sel);
                $('.dept').selectpicker('refresh');
                $(".check").click(function () {
                    if ($(this).val() == "2") {
                        $(".shuru").hide();
                        $(".depts").show();
                    } else {
                        $(".depts").hide();
                        $(".shuru").show();
                    }
                })

            },
            //确认回调
            btn1: function () {
                vm.tianan.jingbanuser = $(".dept").selectpicker('val');
                vm.tianan.lianstatus = $(".check[type='radio']:checked").val();
                if (vm.tianan.lianstatus == '2') {
                    vm.tianan.banjiestatus = 2;

                }
                vm.tianan.bujieshou = $(".liancause").val();
                if( vm.tianan.jingbanuser!=null){

                var url = "sys/tianan/updateyushen";
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.tianan),
                    success: function (r) {
                        if (r.code === 0) {
                            layer.msg("提交成功", {icon: 1});
                            vm.reload();
                        } else {
                            layer.alert(r.msg);

                        }
                    }
                });
                }else {
                    layer.alert("请选择经办人");
                }

                layer.closeAll()
            },


        });
    });


}

var curFiles = [];
var downUrl = [];
var title;

function check(id) {
    $.get(baseURL + "sys/tianan/info/" + id, function (r) {
        vm.tianan = r.tianan;
        layer.open({
            title: vm.tianan.title,
            shade: 0.5,
            type: 1,
            skin: 'layui-layer-molv',
            area: ['800px', '450px'],
            btn: ['通过', '不通过'],
            content: '<form id="test"><div id="test1" style="padding:10px 10px  0 10px">' +
                '<div class="form-group  " style="text-align: center;" > 案由分析</div>' +
                '<div class="form-group wenzi anyoufenxi" style="margin-top: 10px;border: 1px #999 solid;"></div>' +
                '<div class="form-group " style="text-align: center;" > 措施建议</div>' +
                '<div class="form-group wenzi  cuoshijianyi" style="margin-top: 10px;border: 1px #999 solid;"></div>' +
                '<div class=" wenzi renyuan" style=""></div>' +
                '<div class="form-group " style="text-align: center;" > 答复</div>' +
                '<div class="form-group wenzi dafu" style="margin-top: 5px;border: 1px #999 solid; "></div>' +
                // '<div class="form-group " style="text-align: center;" > 上次审核留言</div>' +
                // '<div class="form-group wenzi liancause" style="margin-top: 5px;border: 1px #999 solid; "></div>' +
                '<div class="form-group  user" ></div>' +
                '<div class="form-group ">相关附件：' +
                '<ul id="ulli"></ul></div>' +
                '<div class="neirong input-group" style="background: #F2F2F2; padding: 5px; width: 100%;"></div>' +
                '<textarea  style="margin: 10px;" name=""  placeholder="审核留言 " class="layui-textarea  liancause"></textarea>' +
                '</div></form>',
            success: function (layero, index) {
                $(".neirong").html("");
                $.ajax({
                    type: "POST",
                    url: baseURL + "sys/tianansubmit/listled?tianid="+id,
                    contentType: "application/json",
                    success: function (r) {
                        if (r.code === 0) {
                            if (r.list.length) {
                                $(".neirong").append("<h4 style='color: red;'>院领导审核不通过原因：</h4>");
                                for (var i = 0; i < r.list.length; i++) {
                                    $(".neirong").append("<div class='form-group' style='padding:5px;'> 第"+(i+1)+"次不通过原因："+r.list[i].leacause+"</div>");
                                }

                            }
                        } else {

                        }
                    }
                });
                $(".liancause").val(  vm.tianan.rescause);
                $(".renyuan").html("<p>提案人：" + vm.tianan.creatusername + "&nbsp;&nbsp;&nbsp;所属部门：" + vm.tianan.deptIdName + "</p>")
                $(".anyoufenxi").html("<p>" + vm.tianan.anyoufenxi + "</p>");
                $(".cuoshijianyi").html("<p>" + vm.tianan.cuoshijianyi + "</p>");
                $(".user").html("经办人:" + vm.tianan.jingbanusername + "&nbsp;&nbsp;&nbsp;办理时间：" + vm.tianan.updateTime);
                //评分组件代码
                $(".dafu").html("<p>" + vm.tianan.subexplain + "</p>");
                if (vm.tianan.subfile) {
                    var s = [];
                    s = vm.tianan.subfile.split(",");
                    //遍历所有文件
                    for (var i = 0; i < s.length; i++) {
                        if (s[i] != null && s[i] != 'null') {
                            s[i].replace("/", "\\")
                        }
                        var fileNameIndex = s[i].lastIndexOf("\\");
                        var filePathName = s[i].substring(fileNameIndex + 1);
                        var html = filePathName;
                        downUrl.push(s[i]);

                        html = '<li>' +
                            html + '<a class="operation_type" style="color: #0c74c4; text-decoration:none" href="../../../sys/file/fileDown?fileDir=' + encodeURIComponent(s[i]) + '"  > &nbsp;&nbsp;下载</a>'
                            + "<a class='operation_type'  style='color: #0c74c4;  border:none;text-decoration:none'   onclick='eye( \"" + s[i].replace(/\\/g, "//") + "\")' href='javascript:;'  > &nbsp;&nbsp;预览</a></li>";
                        $("#ulli").append(html);
                    }
                } else {
                    $("#ulli").append("<p>暂无</p>");
                }

            },
            //确认回调
            btn1: function () {


                vm.tianan.rescause = $(".liancause").val();
                vm.tianan.banjiestatus = '4';
                var url = "sys/tianan/updatecheck";
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.tianan),
                    success: function (r) {
                        if (r.code === 0) {
                            layer.msg("提交成功", {icon: 1});
                            vm.reload();
                        } else {
                            layer.alert(r.msg);

                        }
                    }
                });
                layer.closeAll()
            },

            //确认回调
            btn2: function () {


                vm.tianan.rescause = $(".liancause").val();
                vm.tianan.banjiestatus = '-3';
                var url = "sys/tianan/updatecheck";
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.tianan),
                    success: function (r) {
                        if (r.code === 0) {
                            layer.msg("提交成功", {icon: 1});
                            vm.reload();
                        } else {
                            layer.alert(r.msg);

                        }
                    }
                });
                layer.closeAll()
            },

        });
    });


}
var downUrl = [];
var title;
function infos(id) {
    var tianan;
    $.ajax({
        type: "GET",
        url: baseURL + "../sys/tianan/info/" + id,
        cache: false,
        async: false,
        success: function (r) {
            tianan = r.tianan;
            var lianstatu;
            if (tianan.lianstatus == 2||tianan.lianstatus == '2') {
                lianstatu = checkstatus(tianan.banjiestatus)
            } else {
                lianstatu = lianstatus(tianan.lianstatus)

            }
            if(tianan.liantype==3){

                lianstatu = '<span style="color: red">终止</span>';
            }


            layer.open({
                title: tianan.title,
                type: 1,
                skin: 'layui-layer-molv',
                area: ['800px', '450px'],
                content: '<div class="row" style="padding: 10px">' +
                    ' <table class="table table-bordered table-style"> ' +
                    ' <tbody> ' +
                    '<tr><td style="width:110px; ">提案人</td><td style="    width: 140px;">' + isnull(tianan.creatusername) + '</td><td style="width:85px;text-align: center; ">提案类别</td><td>' + isnull(tianan.typesName) + '</td><td style="width:85px;text-align: center; ">所在部门</td><td>' + isnull(tianan.deptIdName) + '</td></tr>' +
                    '<tr><td>案由分析</td><td colspan="5">' + isnull(tianan.anyoufenxi) + '</td></tr>' +
                    '<tr><td>措施建议</td><td colspan="5">' + isnull(tianan.cuoshijianyi) + '</td></tr>' +
                    '<tr><td>办理时限</td><td >' + isnull(tianan.endtime) + '</td><td style="width:85px;text-align: center;">办理类型</td><td>' + isnull(liantype(tianan.liantype)) + '</td><td style="width:85px;text-align: center; ">办理部门</td><td>' + isnull(tianan.liandeptname) + '</td></tr>' +
                    '<tr><td>提案类型</td><td >' + isnull(tianleibie(tianan.type)) + '</td><td style="width:85px;text-align: center;">办理状态</td><td>' + lianstatu + '</td><td style="width:85px;text-align: center; ">提案人满意度</td><td>' + isnull(manyistatus(tianan.manyi)) + '</td></tr>' +
                    '<tr><td>提案答复</td><td colspan="5">' + isnull(tianan.subexplain) + '</td></tr>' +
                    '<tr><td>审核留言</td><td colspan="5">' + isnull( tianan.rescause) + '</td></tr>' +
                    '<tr><td >经办人</td><td >' + isnull(tianan.jingbanusername) + '</td><td>部门负责人审核时间</td><td >' + isnull(tianan.restime) + '</td><td>分管院领导审核时间</td><td>' + isnull(tianan.ledtime) + '</td></tr>' +

                    ' </tbody> ' +
                    '</table>' +
                    '<div class="input-group ">相关附件：<ul id="ulli"></ul></div>' +
                    ' </div>',
                success: function () {

                    if (tianan.subfile != null && tianan.subfile != '') {
                        var s = [];
                        s = tianan.subfile.split(",");
                        //遍历所有文件
                        for (var i = 0; i < s.length; i++) {
                            if (s[i] != null && s[i] != 'null') {
                                s[i].replace("/", "\\")
                            }
                            var fileNameIndex = s[i].lastIndexOf("\\");
                            var filePathName = s[i].substring(fileNameIndex + 1);
                            var html = filePathName;
                            downUrl.push(s[i]);

                            html = '<li>' +
                                html + '<a class="operation_type" style="color: #0c74c4; text-decoration:none" href="../../../sys/file/fileDown?fileDir=' + encodeURIComponent(s[i]) + '"  > &nbsp;&nbsp;下载</a>'
                                + "<a class='operation_type'  style='color: #0c74c4;  border:none;text-decoration:none'   onclick='eye( \"" + s[i].replace(/\\/g, "//") + "\")' href='javascript:;'  > &nbsp;&nbsp;预览</a></li>";
                            $("#ulli").append(html);
                        }
                    } else {
                        $("#ulli").append("<p>无</p>");
                    }
                }
            })
        }
    })
}
function init() {

    $("#jqGridtable").html("");
    $("#jqGridtable").html('<table id="jqGrid"></table><div id="jqGridPager"></div>');
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/tianan/listchuli?sea=' + $("#sea").val() + '&banjiestatus=' + $("#banjiestatus").val(),
        datatype: "json",
        colModel: [
            {label: '提案名称', name: 'title', index: 'title', width: 50},
            {
                label: '立案类型',
                align: 'center',
                sortable: true,
                name: 'liantype',
                index: 'liantype',
                width: 40,
                formatter: function (value, row, rowObject) {

                    return lian(value);
                }
            }, {
                label: '办理时限',
                name: 'endtime',
                index: 'endtime',
                align: 'center',
                width: 40,
            }, {
                label: '标签',
                align: 'center',
                sortable: true,
                name: 'lable',
                index: 'lable',
                width: 40,
            },
            {
                label: '状态',
                name: 'lianstatus',
                index: 'lianstatus',
                align: 'center',
                width: 40,
                formatter: function (value, row, rowObject) {
                    if (rowObject.lianstatus != 2) {
                        return lianstatus(rowObject.lianstatus);
                    } else {
                        return checkstatus(rowObject.banjiestatus);
                    }

                }
            },

            {label: '提案人', align: 'center', sortable: true, name: 'creatusername', index: 'dept_id', width: 40},
            {
                label: '操作',
                name: 'id',
                align: 'center',
                index: 'id',
                width: 50,
                formatter: function (value, row, rowObject) {
                    var but = "";
                    but += ' <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" onclick="info(' + value + ')">详情</button>';
                    if (rowObject.lianstatus == 1) {
                        but += '<button type="button" class="layui-btn layui-btn-xs layui-btn-normal" onclick="checkchuli(' + value + ')">受理</button>';
                    }
                    if (rowObject.banjiestatus == 3) {
                        but += '<button type="button" class="layui-btn layui-btn-xs layui-btn-normal" onclick="check(' + value + ')">审核</button>';
                    }
                    return but;
                }
            }


        ],
        viewrecords: true,
        height: 360,
        rowNum: 10,
        rowList: [10, 30, 50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
        }
    });
}

$(function () {
    init();
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        tiananShenyi: {},
        tianan: {}
    },
    methods: {
        query: function () {
            vm.reload();
        },
        add: function () {
            vm.showList = false;
            vm.title = "新增";
            vm.tiananShenyi = {};
        },
        update: function (event) {
            var id = getSelectedRow();
            if (id == null) {
                return;
            }
            vm.showList = false;
            vm.title = "修改";

            vm.getInfo(id)
        },
        saveOrUpdate: function (event) {
            $('#btnSaveOrUpdate').button('loading').delay(1000).queue(function () {
                var url = vm.tiananShenyi.id == null ? "sys/tiananshenyi/save" : "sys/tiananshenyi/update";
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.tiananShenyi),
                    success: function (r) {
                        if (r.code === 0) {
                            layer.msg("操作成功", {icon: 1});
                            vm.reload();
                            $('#btnSaveOrUpdate').button('reset');
                            $('#btnSaveOrUpdate').dequeue();
                        } else {
                            layer.alert(r.msg);
                            $('#btnSaveOrUpdate').button('reset');
                            $('#btnSaveOrUpdate').dequeue();
                        }
                    }
                });
            });
        },
        del: function (event) {
            var ids = getSelectedRows();
            if (ids == null) {
                return;
            }
            var lock = false;
            layer.confirm('确定要删除选中的记录？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                if (!lock) {
                    lock = true;
                    $.ajax({
                        type: "POST",
                        url: baseURL + "sys/tiananshenyi/delete",
                        contentType: "application/json",
                        data: JSON.stringify(ids),
                        success: function (r) {
                            if (r.code == 0) {
                                layer.msg("操作成功", {icon: 1});
                                $("#jqGrid").trigger("reloadGrid");
                            } else {
                                layer.alert(r.msg);
                            }
                        }
                    });
                }
            }, function () {
            });
        },
        getInfo: function (id) {
            $.get(baseURL + "sys/tiananshenyi/info/" + id, function (r) {
                vm.tiananShenyi = r.tiananShenyi;
            });
        },
        gettiananInfo: function (id) {

        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                page: page
            }).trigger("reloadGrid");
        }
    }
});